//
//  JsBottomInputBarController.m
//  JsUtilityDemo
//
//  Created by Gikki Ares on 2021/8/7.
//

#import "JsBottomInputBarBetaController.h"
#import <JsAsrUtilitySdk/JsBottomInputBarBeta.h>
#import <JsUtilitySdk/JsGeometryManager.h>
#import <JsUtilitySdk/JsDisplayManager.h>
#import <JsUtilitySdk/JsColorManager.h>
//#import <IQKeyboardManager/IQKeyboardManager.h>
#import <JsUtilitySdk/JsBarrageButton.h>

@interface JsBottomInputBarBetaController ()
<JsBottomInputBarBetaDelegate,
JsBarrageButtonDelegate>
{
	JsBottomInputBarBeta * mBottomInputBar;
}
@end

@implementation JsBottomInputBarBetaController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	CGFloat safeAreaBottomHeight = JsGeometryManager.safeAreaInsets.bottom;
	JsBottomInputBarBetaVm * vm = [JsBottomInputBarBetaVm new];
	
	JsBottomInputBarBeta * inputBar = [[JsBottomInputBarBeta alloc] initWithFrame:CGRectMake(0, 200, JsGeometryManager.screenWidth, vm.wrapperContentSize.height) vm:vm];
	mBottomInputBar = inputBar;
	inputBar.delegate = self;
	inputBar.backgroundColor = [UIColor whiteColor];
	JsDisplayStyle * style = [JsDisplayStyle defaulStyle];
	style.displayPosition = JsDisplayPositionBottom;
	style.offset_displayPosition = UIOffsetMake(0, -safeAreaBottomHeight);
	[inputBar displayInView:self.view withDisplayStyle:style undisplayCompletionHandler:nil];
	self.view.backgroundColor = [JsColorManager morandi_lightGray];
//	IQKeyboardManager.sharedManager.enable = NO;
//	[IQKeyboardManager.sharedManager setEnable:NO];
//	[IQKeyboardManager.sharedManager setEnableAutoToolbar:NO];
	
	{
		JsBarrageButtonVm * vm = [JsBarrageButtonVm new];
		JsBarrageButton * button = [[JsBarrageButton alloc]initWithFrame:CGRectMake(200,200, vm.wrapperContentSize.width,vm.wrapperContentSize.height) vm:vm];
		button.delegate = self;
	[self.view addSubview:button];
	}
}


#pragma mark JsBottomInputBarBetaDelegate
#pragma mark 点击了点赞按钮
- (void)jsBottomInputBarBetaClickLike:(JsBottomInputBarBeta *)bar {
	[bar oneMoreLike];
}
//- (void) sendOneBarrageWithMessage:(NSString *)message {
//	[mBarrageRender receive:[self walkTextSpriteDescriptorWithDirection:BarrageWalkDirectionR2L side:BarrageWalkSideRight message:message]];
//}
//	/// 生成精灵描述 - 过场文字弹幕
//- (BarrageDescriptor *)walkTextSpriteDescriptorWithDirection:(BarrageWalkDirection)direction side:(BarrageWalkSide)side message:(NSString *)message{
//	BarrageDescriptor * descriptor = [[BarrageDescriptor alloc]init];
//	descriptor.spriteName = NSStringFromClass([BarrageWalkTextSprite class]);
//	descriptor.params[@"bizMsgId"] = [NSString stringWithFormat:@"%ld",(long)_index];
//		//	descriptor.params[@"text"] = [NSString stringWithFormat:@"过场文字弹幕:%ld",(long)_index++];
//	descriptor.params[@"text"] = message;
//	descriptor.params[@"textColor"] = [UIColor whiteColor];
//	descriptor.params[@"speed"] = @(100 * (double)random()/RAND_MAX+50);
//	descriptor.params[@"direction"] = @(direction);
//	descriptor.params[@"side"] = @(side);
//	descriptor.params[@"clickAction"] = ^(NSDictionary *params){
//		NSString *msg = [NSString stringWithFormat:@"弹幕 %@ 被点击",params[@"bizMsgId"]];
//		NSLog(@"%@",msg);
//	};
//	return descriptor;
//}

#pragma mark 点击了分享按钮
- (void)jsBottomInputBarBetaClickShare:(JsBottomInputBarBeta *)bar{
	NSLog(@"Share!");
}

- (void)jsBottomInputBarBetaClickPick:(JsBottomInputBarBeta *)bar {
	JsBottomInputBarBetaVm * uip = [bar getUiParameter];
	if(uip.mb_isPicked) {
		uip.mb_isPicked = NO;
		[self.view.window displayMessage:@"取消收藏"];
	}
	else {
		uip.mb_isPicked = YES;
		[self.view.window displayMessage:@"收藏成功"];
	}
}

- (void)jsBottomInputBarBetaClickExpress:(JsBottomInputBarBeta *)bar {
//	[self gaoBottomBarClickVoice:bar];
}

//- (void)jsBottomInputBarBetaClickVoice:(JsBottomInputBarBeta *)bar {
//	GaoInputBox * gaoInputBox = [GaoInputBox new];
//	gaoInputBox.delegate = self;
//	NSString * text = [bar draftText];
//	if(text.length) {
//		[gaoInputBox setText:text];
//	}
//
//	if(mb_isSendBarrage) {
//		[gaoInputBox setPlaceholder:@"发弹幕"];
//	}
//	else {
//		[gaoInputBox setPlaceholder:@"写评论"];
//	}
//
//	[gaoInputBox setNeedsLayout];
//	GaoDisplayStyle * style = [GaoDisplayStyle defaulStyle];
//	style.displayPosition = GaoDisplayPositionBottom;
//	style.displayAnimationType = GaoDisplayAnimationTypeNone;
//	[gaoInputBox displayInView:self.view.window withDisplayStyle:style completionHandler:^{
//		NSString * text = [gaoInputBox getText];
//		[bar setDraftText:text];
//	}];
//
//		//becomeFirsttResponder,会直接导致键盘通知被调用.所以,必须先让输入框的位置准备好.
//	[gaoInputBox becomeFirstResponder];
//
	
//}
- (void)jsBottomInputBarBeta:(JsBottomInputBarBeta *)box publishContent:(NSString *)content {
	NSLog(@"Cotent is %@",content);
	[box clearAfterPublish];
//	if(mb_isSendBarrage) {
//		[self sendOneBarrageWithMessage:content];
//	}
//	else {
//		RoomCommentRequestConfig * config = [[RoomCommentRequestConfig alloc]initWithRoomID:self.mstr_roomId discussContent:content discussLevel:0 nick:self.mstr_userNickName];
//		[self.view.window displayToast];
//		[GaoRequestBuilder invokeRequestWithInterfaceConfig:config completion:^(id  _Nonnull resultObject, NSError * _Nonnull error) {
//			[self.view.window undisplayToast];
//			if(resultObject) {
//				NSString * resultCode = ((NSNumber *)(resultObject[@"result"])).description;
//				if([resultCode isEqualToString:@"0"]) {
//					[self.view.window displayMessage:@"评论发表成功..."];
//
//						//发布后,不用刷新列表,因为需要审核.审核后,通过轮询状态的回调更新;
//						//[self tableViewRequestChat:self->mgaoTableView_chat];
//				}
//				else {
//					[self.view.window displayMessage:@"评论发表失败,请稍后再试..."];
//				}
//			}
//			else {
//					//接口返回失败.
//			}
//
//		}];
//	}
//

//	[mgaoBarrageButton setState:1];
//	mb_isSendBarrage = NO;
}


-(void)jsBarrageButton:(JsBarrageButton *)button stateChanged:(int)state {
	switch (state) {
		case 0:{
//			mb_isLoadBarrage = NO;
//			mb_isSendBarrage = NO;
			break;
		}
		case 1:{
//			mb_isLoadBarrage = YES;
//			mb_isSendBarrage = NO;
			[mBottomInputBar setPlaceholder:@"写评论..."];
			break;
		}
		case 2:{
//			mb_isLoadBarrage = YES;
//			mb_isSendBarrage = YES;
			[mBottomInputBar setPlaceholder:@"发弹幕..."];
			[mBottomInputBar awakeInputBox];
			break;
		}
		default:
			break;
	}
}

@end
